srs.ratio=function(data,x,y,n,N,mux){ data=as.name(data); x=x; y=y; n=n; N=N; mux=mux plot(x,y,main=data) r=sum(y)/sum(x); fpc=(1-n/N); s2r=sum((y-r*x)^2)/(n-1) vhat.r=fpc*(1/mux^2)*(s2r/n) bound=2*sqrt(vhat.r) lower=r-bound; upper=r+bound cat("","\n","Results from SRS: Data =",data,"\n",'Estimation method = Ratio','\n',"N =",N,"n =",n,"\n","FPC =",fpc ,"\n","Ratio r =",r,"\n","Vhat r =",vhat.r,"\n","Bound =",bound,"\n","Lower Bound =",lower,"Upper Bound =",upper,"\n","") results=list(r=r,data=data,n=n,N=N,fpc=fpc,vhat.r=vhat.r,bound=bound,lower=lower,upper=upper,s2r=s2r) } # to use the function with its call: # srs.ratio(data,x,y,n,N,mux) # data: name of dataset, in quotes # x: vector (data) # y: vector (data) # n: sample size # N: population size # mux: value of mean of X